<?php

namespace App\Http\Controllers\NonPublicVersion;

use App\Http\Controllers\Curl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class Pay extends Controller
{
    /**
     * 支付成功回调地址
     * @param Request $request
     * @internal param $orderNo 订单号
     * @internal param $payMoney 金额
     * @internal param $resultCode 状态码
     * @internal param $timestamp 签名时间
     */
    public function index(Request $request)
    {
        $orderNo    = $request->get('orderNo','mhxy1771489315');
        $payMoney   = $request->get('payMoney',6);
        $resultCode = $request->get('resultCode',0);
        $timestamp  = time();

        //TODO step 1 校验签名

            //TODO step 2 校验订单号

                //TODO step 3 校验金额

                    //TODO step 4 检验道具数量

                        //TODO step 5 更改订单状态

                        //TODO step 6 通知 CP

        $params = [
            'ActualMoney'    => $payMoney,
            'ResultCode'     => $resultCode,
            'OrderNo'        => $orderNo,
            'ExtensionField' => '4208gzsy43-371-1488879289624',
            'ResultMsg'      => '支付成功',
            'TimeStamp'      => $timestamp,
            'Skey'           => md5($orderNo.$payMoney.$resultCode.$timestamp.config('web.pay_callback.key'))
        ];

        $notifyUrl = 'http://pay3.mxxx.suyougame.com/pay.php?plat=qyzhangshang';

        $params = [
            'url'     => $notifyUrl,
            'isPost'  => true,
            'dataStr' => $params
        ];

        $result = Curl::query($params);
    }
}
